CREATE TABLE [dbo].[tb_TiposDeFuncion]
(
[idTipoFuncion] [int] NOT NULL IDENTITY(1, 1),
[Descripcion] [varchar] (50) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[Jerarquia] [int] NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER [dbo].[updatetb_TiposDeFuncion] ON [dbo].[tb_TiposDeFuncion]
 FOR UPDATE AS 
 IF (update(idTipoFuncion)) begin 
	 SELECT * FROM inserted 
	 IF @@ROWCOUNT = 1 begin 
		 UPDATE tb_Plazas
		 SET TipoDeFuncion = (SELECT idTipoFuncion FROM inserted)
		 WHERE tb_Plazas.TipoDeFuncion = (SELECT idTipoFuncion FROM deleted)
		 UPDATE tb_AperturasDeReestructura
		 SET TipoDeFuncion = (SELECT idTipoFuncion FROM inserted)
		 WHERE tb_AperturasDeReestructura.TipoDeFuncion = (SELECT idTipoFuncion FROM deleted)
		 UPDATE tb_FuncionesLUI
		 SET TipoDeFuncion = (SELECT idTipoFuncion FROM inserted)
		 WHERE tb_FuncionesLUI.TipoDeFuncion = (SELECT idTipoFuncion FROM deleted)
	end  ELSE begin 
		 ROLLBACK TRANSACTION 
 end 
 end
GO
ALTER TABLE [dbo].[tb_TiposDeFuncion] ADD CONSTRAINT [PK_tb_TiposDeFuncion] PRIMARY KEY NONCLUSTERED  ([idTipoFuncion]) ON [PRIMARY]
GO
